package org.davidliebman.android.awesomecube;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;

public class SimplePad extends Mesh {
	public int mMoveEnumeration = 0;
	public int mAlternateImage = 0;
	public int mStartImage = 0;
	
	public SimplePad( Context c) {
		super (c);
	}
	
	public SimplePad (Context c, int mEnum, int mImage, int mSecondImage,  boolean mReversed, int mKey, float x, float y, float z) {
		super (c);
		this.mAlternateImage = mSecondImage;
		this.setMoveEnumeration(mEnum);
		makePad (c, mImage, mReversed,  mKey,  x,  y,  z, MeshPart.SHAPE_SQUARE) ;
	}
	
	public SimplePad (Context c, int mEnum, int mImage, int mSecondImage,  boolean mReversed, int mKey, float x, float y, float z, int mShape) {
		super (c);
		this.mAlternateImage = mSecondImage;
		this.setMoveEnumeration(mEnum);
		makePad (c, mImage, mReversed,  mKey,  x,  y,  z, mShape) ;
	}
	
	public SimplePad (Context c, int mImage, boolean mReversed, int mKey, float x, float y, float z) {
		super(c);
		makePad (c, mImage, mReversed,  mKey,  x,  y,  z, MeshPart.SHAPE_SQUARE) ;

	}
		
	public SimplePad (Context c, int mImage, int mSecondImage, boolean mReversed, int mKey, float x, float y, float z) {
		super(c);
		this.mAlternateImage = mSecondImage;
		makePad (c, mImage, mReversed,  mKey,  x,  y,  z, MeshPart.SHAPE_SQUARE) ;

	}
	
	public void makePad (Context c, int mImage, boolean mReversed, int mKey, float x, float y, float z, int mShape) {

		this.mStartImage = mImage;
		
		this.mFace1 = mImage;
		this.mFace2 = mImage;
		this.mFace3 = mImage;
		
		mMeshParts.clear();
		switch (mKey) {
		case Mesh.FACE_PLANE_X :
			// do something;
			mMeshParts.add ( new MeshPartPlaneX (mImage, mReversed, x,  y, z, mShape)) ;
			mMeshParts.add(null);
			mMeshParts.add(null);
			break;
		case Mesh.FACE_PLANE_Y :
			// do something;
			mMeshParts.add(null);
			mMeshParts.add(new MeshPartPlaneY (mImage, mReversed, x, y, z, mShape));
			mMeshParts.add(null);
			break;
		case Mesh.FACE_PLANE_Z :
			// do something;
			mMeshParts.add(null);
			mMeshParts.add(null);
			mMeshParts.add(new MeshPartPlaneZ (mImage, mReversed, x, y, z, mShape));
			break;
		default: 
			//do nothing;
			break;
		}
	}
	
	public void disableForColors(GL10 gl) {
		   gl.glDisable (GL10.GL_BLEND); 
		   gl.glDisable (GL10.GL_DITHER); 
		   gl.glDisable (GL10.GL_FOG); 
		   gl.glDisable (GL10.GL_LIGHTING); 
		   gl.glDisable (GL10.GL_TEXTURE_2D); 
		   gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
		   gl.glShadeModel (GL10.GL_FLAT);
		   //gl.glClearDepthf(1.0f);
	   }
	
	public void enableAfterColors(GL10 gl) {
		gl.glEnable (GL10.GL_LIGHTING); 
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
		gl.glEnable(GL10.GL_TEXTURE_2D);
		gl.glEnable(GL10.GL_CULL_FACE);
		gl.glEnable(GL10.GL_DEPTH_TEST);
		gl.glShadeModel(GL10.GL_SMOOTH);
		gl.glDepthFunc(GL10.GL_LEQUAL);
		//gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

		gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
		gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
		gl.glColor4x(0xffff, 0xffff, 0xffff, 0xffff);
   }
	public void makeColors(GL10 gl, int i) {
		
		//gl.glColor4x(base + i, 0, 0, alpha);
    	gl.glColor4f ((Picking.getIdNum(i) )/Picking.DEVIDE, 0, 0, 1.0f); 
		
	}

	public void setSelectedArrow() {
		mFace1 = this.mAlternateImage;
		mFace2 = this.mAlternateImage;
		mFace3 = this.mAlternateImage;
	}
	
	public void setStandardArrow() {
		mFace1 = this.mStartImage;
		mFace2 = this.mStartImage;
		mFace3 = this.mStartImage;
	}
	
	public void setBlankArrow() {
		mFace1 = TextureLibrary.BLANK;
		mFace2 = TextureLibrary.BLANK;
		mFace3 = TextureLibrary.BLANK;
	}
	
	public int getMoveEnumeration() {
		return mMoveEnumeration;
	}

	public void setMoveEnumeration(int mMoveEnumeration) {
		this.mMoveEnumeration = mMoveEnumeration;
	}
	
}
